package com.linjacy.container.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.linjacy.container.product.entity.UserEntity;
import com.linjacy.container.product.service.UserService;
import com.linjacy.common.utils.PageUtils;
import com.linjacy.common.utils.R;



/**
 * 
 *
 * @author linjacy
 * @email 939886352@gmail.com
 * @date 2021-01-03 16:04:54
 */
@RestController
@RequestMapping("product/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{uid}")
    public R info(@PathVariable("uid") Long uid){
		UserEntity user = userService.getById(uid);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@Validated @RequestBody UserEntity user){
		userService.saveAuto(user);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);
        return R.ok();
    }
    @RequestMapping("/updateByTableId")
    public R updateByTableId(@RequestBody UserEntity user){
        userService.updateByTableId(user);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] uids){
		userService.removeByIds(Arrays.asList(uids));

        return R.ok();
    }
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
        userService.removeByUid(id);
        return R.ok();
    }

}
